package com.qf.common.exception;
import com.qf.common.result.ResultEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice //实现全局异常处理
@Component
public class ExceptionHandler {

    // 业务异常(程序员手动抛出的异常)
//
    @org.springframework.web.bind.annotation.ExceptionHandler(ShopException.class)
    @ResponseBody
    public ResultEntity businessException(ShopException e) {
        System.out.println("出现了业务异常");
        System.out.println(e);
        return ResultEntity.error(e.getMsg());
    }

    // 系统异常(程序员写的bug)
    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultEntity systemException(Exception e) {
        System.out.println("系统出现异常了");
        System.out.println(e);
        return ResultEntity.error("系统正在维护。请稍后再试。。。");
    }
}
